import axios from '@/libs/api.request'
import { LOGIN, CACHE_MENU, NOTICE_COUNT, LOGOUT } from './list'

// 登录
export const login = ({ userName, password }) => {
  let param = new URLSearchParams()
  param.append('USERNAME', userName)
  param.append('PASSWORD', password)

  return axios.request({
    url: LOGIN,
    data: param,
    method: 'post'
  })
}

// 缓存 menu
export const cacheMenu = () => {
  return axios.request({
    url: CACHE_MENU,
    method: 'get'
  })
}

// 获取 通知数量
export const getNoticeCount = ({ userName, status }) => {
  return axios.request({
    url: NOTICE_COUNT,
    params: {
      USERNAME: userName,
      STATUS: status
    },
    method: 'get'
  })
}

export const getUserInfo = token => {
  return axios.request({
    url: 'get_info',
    params: {
      token
    },
    method: 'get'
  })
}

export const logout = token => {
  return axios.request({
    url: LOGOUT,
    method: 'post'
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
